
// 在Customer类中添加
class Customer {
    private String name;
    private int energyLevel;
    private double balance;

    public Customer(String name, double balance) {
        this.name = name;
        this.energyLevel = 50; // 初始能量水平
        this.balance = balance;
    }

    // Getter和Setter方法
    public String getName() {
        return name;
    }

    public int getEnergyLevel() {
        return energyLevel;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    // 饮用咖啡方法
    public void drinkCoffee(Coffee coffee) {
        this.energyLevel += coffee.getEnergyBoost();
        if (this.energyLevel > 100)
            this.energyLevel = 100;
        System.out.println(name + "喝了" + coffee.getName() + "，能量值增加到" + energyLevel + "%");
    }

    // 支付方法
    public boolean makePayment(double amount) {
        if (balance >= amount) {
            balance -= amount;
            return true;
        } else {
            System.out.println("余额不足！当前余额: ¥" + balance);
            return false;
        }
    }

    // 在Customer类中添加
    public String toFileString() {
        return name + "," + energyLevel + "," + balance;
    }

    public static Customer fromFileString(String data) {
        String[] parts = data.split(",");
        if (parts.length != 3) {
            throw new IllegalArgumentException("无效的顾客数据格式");
        }

        Customer customer = new Customer(parts[0], Double.parseDouble(parts[2]));
        customer.energyLevel = Integer.parseInt(parts[1]);

        return customer;
    }
}
